package com.answeringplayer.controller;

import com.answeringplayer.Bean.Request;
import com.answeringplayer.Bean.Response;
import com.answeringplayer.dto.*;
import com.answeringplayer.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/exam")
public class ExamController {

    @Autowired
    private ExamService examService;

    @PostMapping("/start")
    public Response<StartExamResponseDTO> startExam(@RequestBody Request<StartExamRequestDTO> request) {
        return examService.startExam(request);
    }

    @PostMapping("submit")
    public Response<SubmitAnswerResponse> submitAnswer(
            @RequestParam Long userId,
            @RequestParam Integer bankId,
            @RequestParam String practiceType,
            @RequestBody List<AnswerDTO> answers
    ) {
        System.out.println("=== 接收到提交答案请求 ===");
        System.out.println("User ID: " + userId);
        System.out.println("Bank ID: " + bankId);
        System.out.println("Practice Type: " + practiceType);
        System.out.println("Answers Count: " + answers.size());
        System.out.println("=====================");

        return examService.submitAnswer(userId, bankId, practiceType, answers);
    }

    @GetMapping("practice-records/{userId}")
    public Response<List<PracticeRecordDTO>> getPracticeRecords(@PathVariable Long userId) {
        System.out.println("=== 获取练习记录 ===");
        System.out.println("User ID: " + userId);
        System.out.println("=====================");

        return examService.getPracticeRecords(userId);
    }
}